package ee.ut.sysmodel.bgmn.model;


public class BoardState {
	public static final int PIN_COUNT = 24;
	public static final int P1_SOURCE_BAR = -2;
	public static final int P2_SOURCE_BAR = -1;
	
	private Pin[] pins;
	private Pin p1bar, p2bar;
	private Pin p1goal, p2goal;
	
	// XXX: Those Player instances don't really belong here
	// If there is time, refactor
	public BoardState(Player current, Player opponent) { 
		pins = new Pin[PIN_COUNT];
		
		for(int i = 1; i <= PIN_COUNT; i++) {
			pins[i-1] = new Pin(i);
		}
		
		if(current.getIdentity() == Player.Identity.PLAYER_ONE) {
			p1bar = new Bar(current);
			p1goal = new Goal(current);
			p2bar = new Bar(opponent);
			p2goal = new Goal(opponent);
		} else {
			p1bar = new Bar(opponent);
			p1goal = new Goal(opponent);
			p2bar = new Bar(current);
			p2goal = new Goal(current);
		}
	}
	
	public Pin getPin(int number) {
		switch(number) {
		case P1_SOURCE_BAR:
			return p1bar;
		case P2_SOURCE_BAR:
			return p2bar;
		default:
			return pins[number-1];	
		}
	}
	
	public Pin getGoal(Player player) {
		return player.getIdentity() == Player.Identity.PLAYER_ONE ? p1goal : p2goal;
	}
	
	public Pin[] getAllPins(){
		return pins;
	}
}
